<%@ page import="com.hc.commodity.dao.impl.DeptDaoImpl" %>
<%@ page import="com.hc.commodity.dao.DeptDao" %>
<%@ page import="com.hc.commodity.pojo.Dept" %>
<%@ page import="java.util.List" %>
<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2021/4/9
  Time: 10:31
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" href="../css/bootstrap.min.css">
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>

    <%
        //当前页和每页共展示多少条数
        int pageNo = 1;
        int pageSize = 10;
        //获取请求参数
        String begin = request.getParameter("pageno");
        if (begin != null){
            pageNo = Integer.parseInt(begin);
            if (pageNo == 0){
                pageNo = 1;
            }
        }
        //查询数据库
        DeptDao deptDao = new DeptDaoImpl();
        List<Dept> deptList = deptDao.findByPage((pageNo-1)*pageSize, pageSize);
        //总记录数
        int allNumber = deptDao.findAllNumber();
        //总页数
        int totalPage = allNumber / pageSize;
        if (allNumber%pageSize != 0){
            totalPage++;
        }
        //将结果存入数据域中
        pageContext.setAttribute("deptList",deptList);
        pageContext.setAttribute("pageNo",pageNo);
        pageContext.setAttribute("totalPage",totalPage);
    %>

    <div class="container">
        <ul class="breadcrumb">
            <li><a href="#">员工管理系统</a></li>
            <li><a href="#">部门管理</a></li>
        </ul>
        <div>
            <a href="deplInsert.jsp" class="btn btn-primary"> 新增 </a>
        </div>
        <table class="table table-striped table-hover table-bordered">
            <tr>
                <th>编号</th>
                <th>名称</th>
                <th>地址</th>
                <th>操作</th>
            </tr>
            <c:forEach items="${deptList}" var="dept">
                <tr>
                    <td>${dept.deptno}</td>
                    <td>${dept.dname}</td>
                    <td>${dept.loc}</td>
                    <td>
                        <a href="deplUpdate.jsp?deptId=${dept.deptno}" >修改</a>
                        <a href="deplDelete.jsp?deptId=${dept.deptno}">删除</a>
                    </td>
                </tr>
            </c:forEach>
        </table>

        <div style="float: right">
            <span>当前第：${pageNo}页，共${totalPage}页</span>
            <a href="deplManage.jsp?pageno=1" >首页</a>
            <a href="deplManage.jsp?pageno=${pageNo-1}" >上页</a>
            <a href="deplManage.jsp?pageno=${pageNo+1}" >下页</a>
            <a href="deplManage.jsp?pageno=${totalPage}" >尾页</a>
        </div>
    </div>
<a href="http://www.nlecloud.com/device/131747">aaa</a>
</body>
</html>
